<?php
	$this->breadcrumbs=array(
		'Books'=>array('index'),
		'Checking',
	);
	
	$book = Book::model()->findByAttributes(array('check' => 1, 'idstaff' => null));
	if ($book === null) {
		$book = Book::model()->findByAttributes(array('check' => 0));
	}
	if ($book !== null) {
		$book->check = 1;
		$book->save();
 ?>
 
<h1>Check Book</h1>
<br/>
<div class = 'form'>
	<form action = '?r=Checking/check' method = 'POST' enctype = 'multipart/form-data'>
		<table border = 1 width = 100% height = 100%>
			<tr height = 500>
				<td width = 100%>
					<object
						data = '<?php echo 'resource/'.$book->name; ?>'
						type = 'application/pdf'
						width = 100%
						height = 100%
					/>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<tr>
							<td><image src = '<?php echo $book->urlimage; ?>' width = 100 height = 150 /></td>
							<td>
								<table>
									<tr>
										<td>
											<table>
												<tr>
													<td>Cover:</td>
													<td>
														<input type = 'FILE' name = 'image' value = '<?php echo $book->urlimage; ?>'/>					
													</td>
												</tr>
												<tr>
													<td align = 'RIGHT'>Book name:</td>
													<td>
														<input type = 'TEXT' size = 50 name = 'book' value = '<?php echo $book->name; ?>'/>
														<input type = 'HIDDEN' name = 'id' value = '<?php echo $book->idbook; ?>'/>
													</td>
												</tr>
												<tr>
													<td>Author:</td>
													<td>
														<input type = 'TEXT' size = 50 name = 'author' value = '<?php echo $book->author; ?>'/>
													</td>
												</tr>
											</table>
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan = 2>
					<?php
						$genres = BookGenre::model()->findAllByAttributes(array('idbook' => $book->idbook));
						$genreList;
						foreach(Genre::model()->findAll() as $genre) {
							$temp = "<input type = 'CHECKBOX' name = 'genreList[]' value = '$genre->idgenre'";
							foreach($genres as $id) {
								if ($genre->idgenre == $id->idgenre) {
									$temp .= ' checked';
									break;
								}
							}
							echo $temp.'/>'.$genre->name.' ';
						}
					?>
					<br/>
					<input type = 'SUBMIT' name = 'order' value = 'Delete'/>
					<input type = 'SUBMIT' name = 'order' value = 'Check'/>
				</td>
			</tr>
		</table>
	</form>
</div>

<?php
} else {
	echo 'All books are checked';
}
?>